<?php
namespace app\service;

use app\yhUtil\YhApi;

abstract class Base {
    // use ;
    protected array $param;
    protected array $header;
    protected array $sender;
    protected array $chat;
    protected array $message;

    /**
     * Get the value of param
     */
    public function getParam(): array
    {
        return $this->param;
    }
    public function __construct(array $param = [])
    {
        if($param){
            $this->param = $param;
            $this->setHeader($param['header'])
                ->setSender($param['event']['sender'])
                ->setChat($param['event']['chat'])
                ->setMessage($param['event']['message']);
        }
    }
    /**
     * Get the value of header
     */
    public function getHeader(): array
    {
        return $this->header;
    }

    /**
     * Get the value of sender
     */
    public function getSender(): array
    {
        return $this->sender;
    }

    /**
     * Get the value of chat
     */
    public function getChat(): array
    {
        return $this->chat;
    }

    /**
     * Get the value of message
     */
    public function getMessage(): array
    {
        return $this->message;
    }
    
    public function setHeader(array $header){
        $this->header = $header;
        return $this;
    }
    public function setSender(array $sender){
        $this->sender = $sender;
        return $this;
    }
    public function setChat(array $chat){
        $this->chat = $chat;
        return $this;
    }
    public function setMessage(array $message){
        $this->message = $message;
        return $this;
    }

    public function responseText(string $text) {
        $text = YhApi::Text($text, $this->param);
        $res = $text->run();
        trace($res->getContents(), 'plug.success.push');
        return $res;
    }

    abstract public function run();


}